package com.jevons.muffin.net.observer;

import com.jevons.muffin.net.HttpRequestManager;
import com.jevons.muffin.net.bean.NullObject;
import com.jevons.muffin.net.exception.ResponseException;
import com.jevons.muffin.widget.CustomToast;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.disposables.DisposableHelper;
import io.reactivex.observers.DefaultObserver;

/**
 * 典型的请求任务及回调
 * @author linaisheng
 * Created at 2019/4/12.
 */

public class BasicResObservable<T> extends DefaultObserver<T> {

    @Override
    public void onNext(@NonNull T t) {
        if (t.getClass().getName().equals(NullObject.class.getName())) {
            responseSuccess(null);
        } else {
            responseSuccess(t);
        }
    }

    @Override
    public void onError(@NonNull Throwable throwable) {
        responseError(BaseDisposable.dealThrowable(throwable));
        throwable.printStackTrace();
    }

    @Override
    public void onComplete() {

    }

    public void responseSuccess(T response) {

    }

    public void responseError(ResponseException exception) {

    }


    public void cancelRequest() {
        cancel();
    }

}
